using System;
using System.Collections.Generic;
using NobleTech.Products.CreatureKingdom.Utils;

namespace NobleTech.Products.CreatureKingdom
{
    delegate void ChildQuadrantEventHandler(IQuadrant child, IQuadrant parent);

    internal interface IQuadrant
    {
        /// <summary>
        /// The area covered by this Quadrant
        /// </summary>
        /// <remarks>
        /// The top left corner is included in the area, the bottom right isn't
        /// </remarks>
        RectangleD Area { get; }

        /// <summary>
        /// Whether this Quadrant contains any Organisms
        /// </summary>
        bool IsEmpty { get; }

        /// <summary>
        /// The largest Organism in this Quadrant
        /// </summary>
        Organism LargestOrganism { get; }

        /// <summary>
        /// Get Organisms in this Quadrant
        /// </summary>
        /// <param name="bounds">The area all the organisms returned must be within</param>
        /// <param name="minSize">The minimum Size of Organisms to return</param>
        /// <returns>A collection of Organisms</returns>
        IEnumerable<Organism> GetContainedOrganisms(RectangleD bounds, double minSize);

        /// <summary>
        /// Add a new Organism to this Quadrant
        /// </summary>
        /// <param name="organism">The Organism to add to this Quadrant</param>
        /// <returns>The Quadrant with the Organism added to it</returns>
        void AddOrganism(Organism organism);

        /// <summary>
        /// Remove the largest organism in this Quadrant
        /// </summary>
        /// <returns>The Organism removed</returns>
        Organism RemoveLargestOrganism();

        /// <summary>
        /// Get the smallest Quadrant containing a given area
        /// </summary>
        /// <param name="bounds">The area required</param>
        /// <returns>The smallest Quadrant containing the given area</returns>
        IQuadrant GetSmallestQuadrantContaining(RectangleD bounds);

        /// <summary>
        /// Create a new Quadrant or alter this one so that it is extended towards the given point
        /// </summary>
        /// <param name="towards"></param>
        /// <returns></returns>
        IQuadrant Extend(PointD towards);

        #region Turn Steps

        void GetMove();
        void UpdateInfo();
        void DoInteraction();
        void DoMove();
        void DoLifeEvents();

        #endregion

        /// <summary>
        /// Fired when the largestOrganism within this Quadrant is larger than it was
        /// </summary>
        event ChildQuadrantEventHandler OrganismGrown;
    }
}
